import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        //n位自幂数
        for (int i = 1; i <= 999999; i++) {
            int count = 0;//记录位数
            int tmp = i;//将i赋值给tmp
            //求i是几位数
            while (tmp != 0) {
                tmp = tmp / 10;
                count++;
            }
            tmp = i;
            int sum = 0;
            //判断是否为水仙花数
            while(tmp!=0){
                sum+=Math.pow(tmp%10,count);
                tmp/=10;
            }
            if(sum==i){
                System.out.println(i+"是自幂数");
            }
        }
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入两个数字中间用空格隔开");
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = 0;
        //辗转相除法
        while(a % b != 0){
            c = a % b;
            a = b;
            b = c;
        }
        System.out.println(b);
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for (; i <= Math.sqrt(n); i++) {
            //2种情况：1、不符合循环条件    2、遇到了break
            //判断是不是素数
            if (n % i == 0) {
                System.out.println(n + "不是素数");
                break;
            }
        }
        if(i>Math.sqrt(n))
        {
            System.out.println(n+"是素数");
        }

    }
}
